If your application provides this business logic, it will need to choose which outputs to spend first. There are a few different algorithms which can lead to different results. An example CGI program and description of all the parameters which can be used in the Payment Protocol is provided in the Developer Examples Payment Protocol...