I am choosing between multiple shipping locations which is the shortest distance. I have the process running the lines through a google distance api and appending the distance (in meters) to the different line options. So what I have is a bunch of one line files that are product, country, shiptozip, site, shipfromzip, distance. I was going to sort the lines by distance, then drop the duplicates based on the right values and then run them into a document cache, and pull the site from the cache later on in the process. The problem with my plan is that I cannot figure out how to sort the files by the distance. I think the problem is that the script I am using How to Sort a group of Documents using Groovy is not doing a mathematical sort.

So I need to either figure out how to do a mathematical sort, or maybe someone can point out a simpler method that I hadn't thought of. I can think of some ways to do it with dynamic process properties and scripting, but that sounds like a mess and I'd prefer to avoid that.

This turned out to be a pretty simple solution. With the original script from How to Sort a group of Documents using Groovy. I was getting it sorted as shown. Which is as intended by this script:

1243818

1243818

3184704

3826180

3826180

3826180

4490239

4490239

737283

737283

737283

It turns out that if you want to sort this by integer value yet preserve the unique values that this script is already adding by appending _# to the end of it (this prevents document loss). All you need to do is figure out what is the biggest possible number you will have and prepend zeroes to all your numbers to that number of digits. The greatest distance between two points in the US is around 4.65 million meters so 7 digits will cover more than twice that distance.

This gave me the desired sort order:

0737283

0737283

0737283

1243818

1243818

3184704

3826180

3826180

3826180

4490239

4490239

Important Note - I had to change my outgoing profile AND my incoming profile distance field from Data Type: Number to Character for this to work.