def build_ship_confirm(origin, destination, packages, options={})

      #Return Service types:
      #‘2’ = UPS Print and Mail (PNM)
      #‘3’ = UPS Return Service 1- Attempt (RS1)
      #‘5’ = UPS Return Service 3-Attempt (RS3)
      #‘8’ = UPS Electronic Return Label (ERL)
      #‘9’ = UPS Print Return Label (PRL)


      packages = Array(packages)
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.ShipmentConfirmRequest {
          xml.Request {
            xml.RequestAction 'ShipConfirm'
            xml.RequestOption options[:nonvalidate] ? 'nonvalidate' : 'validate'
          }
          xml.Shipment {
            build_location_node(['Shipper'], (options[:shipper] || origin), options, xml)
            build_location_node(['ShipTo'], destination, options, xml)
            if options[:shipper] && options[:shipper] != origin
              build_location_node(['ShipFrom'], origin, options, xml)
            end
            xml.PaymentInformation {
              xml.Prepaid {
                xml.BillShipper {
                  xml.AccountNumber options[:origin_account]
                }
              }
            }
            if options[:return_service_code].present?
              xml.ReturnService {
                xml.Code options[:return_service_code]
                # if options[:return_service_description].present?
                #   xml.Description options[:return_service_description]
                # end
              }
            end
            xml.Service {
              xml.Code options[:service]
            }
            xml.ShipmentServiceOptions {
              xml.SaturdayDelivery if options[:saturday] == true
              if options[:delivery_confirmation_type].present?
                xml.DeliveryConfirmation {
                  xml.DCISType options[:delivery_confirmation_type]
                }
              end
            }
            packages.each do |package|
              imperial = ['US', 'LR', 'MM'].include?(origin.country_code(:alpha2))
              xml.Package {
                xml.PackagingType {
                  xml.Code package.options[:package_type]
                }
                xml.Dimensions {
                  xml.UnitOfMeasurement {
                    xml.Code imperial ? 'IN' : 'CM'
                  }
                  [:length, :width, :height].each do |axis|
                    value = ((imperial ? package.inches(axis) : package.cm(axis)).to_f*1000).round/1000.0 # 3 decimals
                    xml.send axis.to_s.gsub(/^[a-z]|\s+[-z]/) { |a| a.upcase }, [value, 0.1].max
                  end
                }
                xml.PackageWeight {
                  xml.UnitOfMeasurement {
                    xml.Code imperial ? 'LBS' : 'KGS'
                  }
                  value = ((imperial ? package.lbs : package.kgs).to_f*1000).round/1000.0 # decimals
                  xml.Weight [value, 0.1].max
                }
                xml.Description package.options[:package_description] if package.options[:package_description].present?
                xml.PackageServiceOptions {
                  if package.options[:delivery_confirmation_type].present?
                    xml.DeliveryConfirmation {
                      xml.DCISType package.options[:delivery_confirmation_type]
                    }
                  end
                }
                if package.options[:references].present?
                  package.options[:references].each do |reference|
                    xml.ReferenceNumber {
                      xml.Code reference[:code]
                      xml.Value reference[:value]
                      if reference[:barcode]
                        xml.BarCodeIndicator
                      end
                    }
                  end
                end
              }
            end
            xml.LabelSpecification {
              xml.LabelPrintMethod {
                xml.Code 'GIF'
              }
              xml.LabelImageFormat {
                xml.Code 'PNG'
              }
            }
          }
        }
      end
      builder.to_xml
    end
def build_ship_confirm(origin, destination, packages, options={})

      #Return Service types:
      #‘2’ = UPS Print and Mail (PNM)
      #‘3’ = UPS Return Service 1- Attempt (RS1)
      #‘5’ = UPS Return Service 3-Attempt (RS3)
      #‘8’ = UPS Electronic Return Label (ERL)
      #‘9’ = UPS Print Return Label (PRL)


      packages = Array(packages)
      builder = Nokogiri::XML::Builder.new do |xml|
        xml.ShipmentConfirmRequest {
          xml.Request {
            xml.RequestAction 'ShipConfirm'
            xml.RequestOption options[:nonvalidate] ? 'nonvalidate' : 'validate'
          }
          xml.Shipment {
            build_location_node(['Shipper'], (options[:shipper] || origin), options, xml)
            build_location_node(['ShipTo'], destination, options, xml)
            if options[:shipper] && options[:shipper] != origin
              build_location_node(['ShipFrom'], origin, options, xml)
            end
            xml.PaymentInformation {
              xml.Prepaid {
                xml.BillShipper {
                  xml.AccountNumber options[:origin_account]
                }
              }
            }
            if options[:return_service_code].present?
              xml.ReturnService {
                xml.Code options[:return_service_code]
                # if options[:return_service_description].present?
                #   xml.Description options[:return_service_description]
                # end
              }
            end
            xml.Service {
              xml.Code options[:service]
            }
            xml.ShipmentServiceOptions {
              xml.SaturdayDelivery if options[:saturday] == true
              if options[:delivery_confirmation_type].present?
                xml.DeliveryConfirmation {
                  xml.DCISType options[:delivery_confirmation_type]
                }
              end
            }
            packages.each do |package|
              imperial = ['US', 'LR', 'MM'].include?(origin.country_code(:alpha2))
              xml.Package {
                xml.PackagingType {
                  xml.Code package.options[:package_type]
                }
                xml.Dimensions {
                  xml.UnitOfMeasurement {
                    xml.Code imperial ? 'IN' : 'CM'
                  }
                  [:length, :width, :height].each do |axis|
                    value = ((imperial ? package.inches(axis) : package.cm(axis)).to_f*1000).round/1000.0 # 3 decimals
                    xml.send axis.to_s.gsub(/^[a-z]|\s+[-z]/) { |a| a.upcase }, [value, 0.1].max
                  end
                }
                xml.PackageWeight {
                  xml.UnitOfMeasurement {
                    xml.Code imperial ? 'LBS' : 'KGS'
                  }
                  value = ((imperial ? package.lbs : package.kgs).to_f*1000).round/1000.0 # decimals
                  xml.Weight [value, 0.1].max
                }
                xml.Description package.options[:package_description] if package.options[:package_description].present?
                xml.PackageServiceOptions {
                  if package.options[:delivery_confirmation_type].present?
                    xml.DeliveryConfirmation {
                      xml.DCISType package.options[:delivery_confirmation_type]
                    }
                  end
                }
                if package.options[:references].present?
                  package.options[:references].each do |reference|
                    xml.ReferenceNumber {
                      xml.Code reference[:code]
                      xml.Value reference[:value]
                      if reference[:barcode]
                        xml.BarCodeIndicator
                      end
                    }
                  end
                end
              }
            end
            xml.LabelSpecification {
              xml.LabelPrintMethod {
                xml.Code 'GIF'
              }
              xml.LabelImageFormat {
                xml.Code 'PNG'
              }
            }
          }
        }
      end
      builder.to_xml
    end
Build the ship_confirm XML request