We propose an algorithm for maximizing the lifetime of a wireless sensor network when there is a mobile sink and the underlying application can tolerate some degree of delay in delivering the data to the sink. Our main contribution is that the algorithm is distributed, and in addition, mostly uses local information. Such an algorithm can be implemented by parallel and/or distributed execution and the overhead of message passing is low. It is also possible to embed the algorithm into a network protocol so that the senor nodes and the sink can run it directly as part of the network operation. Our second contribution is that we give a proof of the algorithm's optimality and the boundedness of the queue sizes, both in the long-run average sense. The proof is based on analyzing a Lyapunov drift.