This is a generalisation of an old puzzle. We assume that you can pour water into a jug until it is full, that you can pour water from one jug into another until either the first is empty or the second is full, and that you can empty a jug. You should also assume that you have a fourth container of unknown capacity $> D$, and that you can only pour fluid into the container but not remove it.
That way you can measure various amounts of water. For example, fill the first jug with $A$ liters. If $B < A$, pour water from the first to the second jug until it is full, so the first jug contains $A-B$ and the second contains $B$.
So you write down all the ways that you can produce various amounts of fluid. And then you write an algorithm that tries out possibilities and finds one that fills the last container with $D$.
Your headline describes a slightly different problem.