The online-to-offline (O2O) platform is becoming increasingly popular in today's market. This study investigates the decision-making problem of an O2O freight platform facing uncertain demand and carbon emission constraints to achieve sustainable development and establish an environment-friendly image. By receiving customer orders online and then delivering them offline, the platform chooses the optimal dispatching time and pricing level to maximize its profit under a limited carbon cap. We consider a stochastic model with two kinds of demand functions, i.e., additive and multiplicative cases, and solve the optimization problems. By adopting a data set from a leading O2O freight platform in China, we find that the proposed model can effectively increase the revenue of the platform by more than 20 % if the platform increases the price appropriately. The results further show that market parameters such as potential market size and price elasticity have a more significant influence on the price decision than logistics parameters such as the fixed shipping cost and holding cost per unit volume per unit time, while logistics parameters affect the dispatching time decision more significantly than market parameters. With respect to the profit, as the carbon cap increases, the profit of the platform first climbs up to a peak point and then decreases with the further increase of the cap due to rising inventory holding costs. Furthermore, the O2O platform can benefit from a large-scale market and thus might suffer a loss at its start-up stage. Our study contributes to the literature on the O2O platform and the freight transportation planning with the consideration of sustainable development.