private ShippingMethodAndRate GetShippingRateInfo(ShippingMethodDto.ShippingMethodRow row, Shipment shipment)
        {
            ShippingMethodAndRate returnRate = null;
            string nameAndRate = string.Empty;

            // Check if package contains shippable items, if it does not use the default shipping method instead of the one specified
            Type type = Type.GetType(row.ShippingOptionRow.ClassName);

            if (type == null)
            {
                throw new TypeInitializationException(row.ShippingOptionRow.ClassName, null);
            }

            string           outputMessage = string.Empty;
            IShippingGateway provider      = (IShippingGateway)Activator.CreateInstance(type);

            if (shipment != null)
            {
                ShippingRate rate = provider.GetRate(row.ShippingMethodId, shipment, ref outputMessage);
                nameAndRate = string.Format("{0} : {1}", row.Name, rate.Money.Amount.ToString("C"));
                returnRate  = new ShippingMethodAndRate(row.Name, nameAndRate, rate.Money.Amount, row.ShippingMethodId);
            }

            return(returnRate);
        }
        private void AddShipping(Cart c, OrderAddress shippingAddress)
        {
            foreach (Shipment ship in c.OrderForms[0].Shipments)
            {
                ship.Delete();
            }

            Shipment shipment = c.OrderForms[0].Shipments.AddNew();

            shipment.ShippingAddressId = shippingAddress.Name;

            for (int i = 0; i < c.OrderForms[0].LineItems.Count; i++)
            {
                LineItem item = c.OrderForms[0].LineItems[i];
                shipment.AddLineItemIndex(i, item.Quantity);
            }

            if (c.OrderForms[0].Shipments != null && c.OrderForms[0].Shipments.Count > 0)
            {
                shipment = c.OrderForms[0].Shipments[0];
                ShippingMethodAndRate selectedShippingMethod = GetSelectedShippingMethod();

                if (selectedShippingMethod != null)
                {
                    shipment.ShippingMethodId   = selectedShippingMethod.ShippingMethodId;
                    shipment.ShippingMethodName = selectedShippingMethod.ShippingMethodName;
                    c.AcceptChanges();
                }
            }

            c.AcceptChanges();
        }
        private ShippingMethodAndRate GetSelectedShippingMethod()
        {
            ShippingMethodAndRate selectedShippingMethod = null;

            var shippingMethods = ShippingManager.GetShippingMethodsByMarket(_currentMarket.GetCurrentMarket().MarketId.Value, false);

            // TODO: Make this configurable, as we do not specify
            // shipping during checkout in
            var selectedShipping = shippingMethods.ShippingMethod.FirstOrDefault(m => m.IsActive && m.IsDefault);

            if (selectedShipping == null)
            {
                throw new ApplicationException("No active and default shipping method for current market (" + _currentMarket.GetCurrentMarket().MarketId.Value + ")");
            }

            Guid   methodId   = selectedShipping.ShippingMethodId;
            string methodName = selectedShipping.DisplayName;

            decimal rate = 100m;

            selectedShippingMethod = new ShippingMethodAndRate(methodName, string.Empty, rate, methodId);

            return(selectedShippingMethod);
        }