def METHOD_NAME(self, carrier, format):
    import karrio
    from karrio.core.utils import DP
    from karrio.providers.generic.units import SAMPLE_SHIPMENT_REQUEST
    template = carrier.label_template
    data = (
        template.shipment_sample
        if template is not None and len(template.shipment_sample.items()) > 0
        else SAMPLE_SHIPMENT_REQUEST
    )
    service = data.get("service") or next(
        (s.service_code for s in carrier.services)
    )
    request = DP.to_object(
        datatypes.ShipmentRequest,
        {
            **data,
            "service": service,
            "label_type": format.upper(),
            "selected_rate_id": data.get("selected_rate_id") or "",
            "rates": data.get("rates") or [],
        },
    )
    shipment, _ = karrio.Shipment.create(request).from_(carrier.gateway).parse()
    if shipment is None:
        raise Exception("Failed to generate label")
    return shipment.docs.label