code: public function onPrepare(ResourceEventInterface $event)
      {
          $order = $this->getSaleFromEvent($event);
  
          if (!OrderStates::isStockableState($order->getState())) {
              throw new IllegalOperationException(
                  "Order is not ready for shipment preparation"
              );
          }
      }
docs: Prepare event handler.
  
  @param ResourceEventInterface $event
  
  @throws IllegalOperationException