public ItemFulfillmentItemList addToExistingItemList(ItemFulfillmentItemList oldList, ItemFulfillmentLine fulfillmentLine)
        {
            int oldCount = oldList.item.Length;
            int newCount = oldCount + 1;
            ItemFulfillmentItemList newFulfillmentList = new ItemFulfillmentItemList();
            ItemFulfillmentItem[] newItem = new ItemFulfillmentItem[1];
            ItemFulfillmentItem[] newList = new ItemFulfillmentItem[newCount];
            oldList.item.CopyTo(newList, 0);

            newItem[0] = new ItemFulfillmentItem();
            RecordRef item = new RecordRef();
            item.type = RecordType.inventoryItem;
            item.typeSpecified = true;
            item.name = fulfillmentLine.item.ItemName;
            item.internalId = fulfillmentLine.item.itemRecord.internalId;
            newItem[0].item = item;

            newItem[0].quantity = fulfillmentLine.QuantityRequested;
            newItem[0].quantitySpecified = true;

            newItem.CopyTo(newList, oldCount);
            newFulfillmentList.item = newList;

            return newFulfillmentList;
        }
        public List<ItemFulfillmentLine> createNewItemFulfillmentLines(ItemFulfillmentItemList oldItemList)
        {
            List<ItemFulfillmentLine> newItemList = new List<ItemFulfillmentLine>();
            bool flag = false;
            foreach (var line in oldItemList.item)
            {
                ItemFulfillmentLine newLine = new ItemFulfillmentLine(line.item.name, line.quantity, flag);
                newItemList.Add(newLine);
            }

            return newItemList;
        }
        public ItemFulfillment(SalesOrder salesOrder)
        {
            itemFulfillment = new com.netsuite.webservices.ItemFulfillment();
            RecordRef salesOrderID = new RecordRef();
            salesOrderID.type = RecordType.salesOrder;
            salesOrderID.typeSpecified = true;
            salesOrderID.internalId = salesOrder.salesOrder.internalId;

            itemFulfillment.createdFrom = salesOrderID;

            ItemFulfillmentItemList itemFulItemList = new ItemFulfillmentItemList();
            int i = 0;
            ItemFulfillmentItem[] Items = new ItemFulfillmentItem[salesOrder.salesOrder.itemList.item.Count()];

            Dictionary<string, double> binQuantities = new Dictionary<string, double>();

            foreach (var itemLine in salesOrder.salesOrder.itemList.item)
            {
                Items[i] = new ItemFulfillmentItem();
                RecordRef item = new RecordRef();
                item.type = RecordType.inventoryItem;
                item.typeSpecified = true;
                item.internalId = itemLine.item.internalId;
                Items[i].item = item;
                Items[i].quantity = itemLine.quantity;
                Items[i].quantitySpecified = true;
                Items[i].orderLine = itemLine.line;
                Items[i].orderLineSpecified = true;

                binQuantities = getBins(itemLine.item.name);

                string[] bins = new string[binQuantities.Count];
                int j = 0;
                foreach (var key in binQuantities)
                {
                    bins[j] = key.Key;
                    j++;
                }

                Array.Sort(bins, new AlphanumComparatorFast());
                bins = bins.Where(x => !string.IsNullOrEmpty(x)).ToArray();

                List<string> notPreferredBins = new List<string>();
                List<string> preferredBins = new List<string>();
                List<string> orderedBins = new List<string>();

                Regex regex = new Regex("[0-9]+[A-Z]");
                string C = "C";

                foreach (var bin in bins)
                {
                    Match match = regex.Match(bin);
                    if (match.Success)
                    {
                        string letter = (match.Value[match.Value.Length - 1]).ToString();
                        int compare = string.Compare(letter, C);
                        if (compare < 0)
                        {
                            notPreferredBins.Add(bin);
                        }
                        else preferredBins.Add(bin);
                    }
                }

                foreach (var bin in preferredBins)
                {
                    orderedBins.Add(bin);
                }
                orderedBins.Add("Stock");
                foreach (var bin in notPreferredBins)
                {
                    orderedBins.Add(bin);
                }

                foreach (var bin in orderedBins)
                {
                    double availQuantity = binQuantities[bin];
                    if (availQuantity >= Items[i].quantity)
                    {
                        Items[i].binNumbers = bin;
                        break;
                    }
                }
                i++;
            }
            itemFulItemList.item = Items;
            this.itemFulfillment.itemList = itemFulItemList;
        }