Recently I asked this question:
Find Common Values in several arrays, or lists VB.NET
I am trying to make an intelligent stock pick/dispatch location system at the point of invoice from a stock database. Multiple locations are available to dispatch from, and essentially I want to make efficient dispatch, so if all items purchased can be dispatched from one location, they are grouped and dispatched as such, but if not, it groups what it can and dispatches the rest from wherever the highest stock level is available.
Having thought about it a bit more over the holiday I don’t think I can approach it that way.
Two reasons
- Because the number of locations has to be variable, this system is scalable.
- Because the number of items is also scalable
So, instead of listing suitable stock locations, I am now listing the quantity of stock available in each location for the respective items.
Items Locations
_________|__1___|___2__|__3__| - this is location IDs
Item 1 | 3 , 4 , 1 - this is the qty of stock available
Item 2 | 2 , 4 , 0
Item 3 | 1 , 3 , 1
Item 4 | 6 , 1 , 3
I can turn this into a string which might be used to split and create arrays
ie
stockDetails = "3,4,1|2,4,0|1,3,1|6,1,3"
Here, the comma separated values are quantity of available stock in each stock location and the pipes separate the individual items, so the table above is translated to the string above.
I am not keen on multi-dimensional arrays and don’t know how I’d create one without knowing how many stock locations there are.
We can safely assume
- That the stock quantities are in the correct order to correlate back to the stock locations IDs.
- Each pipe separate series of comma separated values will have the same number of comma separated values.
I just can’t work out how to determine the pick locations!
In the above example, all four items can actually be picked from stock location 1, providing only one of each item is purchased. Suppose though a customer bought 2 of item 3. Then the pick would have to be from location 2. All kinds of other scenarios can of course be presented depending on the number of items purchased, the quantity of items purchased and how many stock locations there are to pick from.
I started off simply picking from the location with the highest available stock, but that made no sense when stock was available to pick from more than one locaton because we ended up with multiple dispatch locations which was not necessary.
How can I analyse these variable length strings/arrays to determine the most intelligent way to dispatch.
I can work it out from the stock table with my human brain very well, but cannot see how to program VB.NET to do it!
Please help with VB examples, and also, although I appreciate the help on my original question and I did not specify, I cannot use Linq as I am on .NET 2.0 framework.
If this were my application, I would create a small class that, for each location, would hold a list of the available quantities for each requested product.
Upon retrieving the data, I would create a collection of these location classes for each location that had inventory for at least one of the products.
I would then have a method that provides a weight to indicate the percentage of products that can be fulfilled from that location. I would also probably have a method to indicate distance from the location to the delivery location, if known.
The location class would implement IComparable using the percentage of products and distance as the comparison metrics so that the items could be sorted within the collection.
To determine the locations the order would be fulfilled from, I would do the following:
1) Sort the list of locations and select the first one in the list. If the locations are known, this will also be the one closest to the delivery location.
2) If the location selected in step 1 did not satisfy 100% of the order, cycle through the list of locations and remove the products that were satisfied by the selected location. If a given location is at 0%, remove it from the collection of locations.
3) If all products have not been picked and there are still locations in the list, restart from step 1.
Hopefully this helps you get on the right track.
Update
Here is something to get you started.
This is a start on the location class
Here is a collection class for the above item that performs a lot of the work
Finally, here is an extract from a form that can be used to load the inventory and calculate where a given item will be sourced from:
Update
Here is a .Net 2.0 version of the CalculateInventory method: