One of the main tasks in the planning of production processes is to satisfy the needs of the customers in terms of quantity, quality and time. The issue of the timely execution of production orders is becoming increasingly important. Based on the conducted studies it can be concluded that the size of the delay depends on the adopted scheduling of orders. This paper focuses on the problem of implementing a scheduling of production orders that will allow to avoid delays, and in the event such a scheduling is not possible, for minimizing the sum of delays of all the orders. A new algorithm has been proposed that allows to determine of the optimal sequence of production orders with the minimum sum of delays. The considerations have been limited to the issue of a two-machine system in which the orders are carried out in a flow.