We study the optimization of dynamical systems exhibiting variable time delays. We consider time-varying delays, and delays implicitly defined by input variables as they appear in systems involving fluid transport phenomena. We establish the necessary optimality conditions. Simulations results are presented.