The optimal speed trajectory for a heavy-duty truck is calculated using the Pontryagin's maximum principle. The truck motion depends on controllable tractive and braking forces and external forces such as air and rolling resistance and road slope. The velocity of the vehicle is restricted to be within a driving corridor which consists of an upper and a lower boundary. Simulations are performed on data from a test cycle commonly used for testing distribution driving. The data include road slope and a speed reference, from which the driving corridor is created automatically. The simulations include a sensitivity analysis on how changes in the parameters for the driving corridor influence the energy consumption and trip time.For the widest driving corridor tested, 15.8 % energy was saved compared to the most narrow corridor without increasing the trip time. Most energy was saved by reducing the losses due to braking and small amounts of energy were saved by reducing the losses due to air resistance. Finally, optimal trajectories with the same trip time derived from different settings on the driving corridor are compared in order to analyse energy efficient driving patterns.