In this paper, a manufacturing system composed by a single machine, a buffer and a stochastic demand is considered. The objective is to determine the optimal or near optimal buffer level taken into account the delivery time and the machine failures to minimize the sum of inventory, transportation and lost sales costs. A simulation algorithm based on perturbation analysis is proposed to determine this optimal buffer level in the presence of delivery time.