
io.sphere.client.shop.model.ZoneRate Maven / Gradle / Ivy
package io.sphere.client.shop.model;
import java.util.ArrayList;
import java.util.Currency;
import java.util.List;
import javax.annotation.Nonnull;
import io.sphere.client.model.EmptyReference;
import io.sphere.client.model.Reference;
/** ZoneRate defines shipping rates (prices) for a specific zone. Shipping rates is an array because the rates for
* different currencies can be defined. Used in {@link ShippingMethod}. */
public class ZoneRate {
@Nonnull private Reference zone = EmptyReference.create("zone");
@Nonnull private List shippingRates = new ArrayList();
// for JSON deserializer
private ZoneRate() {}
/** The zone. */
@Nonnull public Reference getZone() { return zone; }
/** The shipping rates for the zone. The list does not contain two shipping rates with the same currency. */
@Nonnull public List getShippingRates() { return shippingRates; }
/** @return a shipping rate for a specific currency.
* null if a rate for the given currency does not exist. */
public ShippingRate getShippingRate(Currency currency) {
for (ShippingRate rate: shippingRates) {
if (rate.getPrice().getCurrencyCode().equals(currency.getCurrencyCode()))
return rate;
}
return null;
}
@Override
public String toString() {
return "ZoneRate{" +
"zone=" + zone +
", shippingRates=" + shippingRates +
'}';
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy