It depends on the delivery service, and it depends on the package, and it depends on the location. We can't give you a definitive answer without more information about the apartment and how it is set up.
Mail and packages are misdelivered all the time; there is certainly no law against it. In cases where delivery is direct to the recipient— the U.S. Postal Service to an official mailbox, or via delivery or courier service whether signed for at the door or left at the door— you will generally have no problem.
There are various relevant regulations in the Domestic Mail Manual, notably under Recipient Options. Broadly speaking, however the recipient's name is mainly of interest because there are provisions where a certain recipient wants to block mail from being delivered to an address— a change of address form, refusal from a certain sender, vacation holds, refusal of sexually explicit material, and so forth. The rules for commercial services are governed by their Conditions of Carriage document, for instance see FedEx and UPS.
But there are certainly cases where you may not reliably receive mail or packages addressed to you at a particular location, namely large buildings and institutions. In some cases, either the Postal Service, or private delivery/courier services, or both may deliver to some agent of a large building or institution like a high-rise apartment, condominium complex, or student dormitory. They will essentially never deliver to individual rooms of places like hotels or hospitals. In all such cases, the building has a mailroom, concierge, or other office that accepts the mail and packages and distributes it internally.
In some cases, packages too large to fit in the mailbox will be placed in a locker, and the key to the locker (or the combination or keycode) placed in your mailbox. But in older buildings, the volume of deliveries may be overwhelming, and they may make you jump through some hoops.
I lived in such a high-rise. The front desk signed for all USPS packages, then left a slip in the unit's mailbox to claim it. If you didn't have the key to the mailbox, or you lost the slip, you could go down and tell them the unit number and show ID that matched the recipient name. But FedEx and UPS packages went to the building concierge, and they would refuse any package addressed to someone who was not on the official list of building residents. They didn't want to take up scarce storage space for misdelivered packages, and didn't want the liability for returning unclaimed ones. It was easier simply to refuse delivery to anyone they didn't recognize.
One way to deal with this problem is to have the package addressed in care of the owner or other registered tenant, as others have suggested:
c/o Owner's Name
1234 Main St, Apt 789
Anytown, US 87654
Hold for pickup
If the package requires that the recipient sign for it, and you are unavailable, it may be held at the post office or distribution center until you can pick it up. You can also deliberately send packages poste restante, which is called General Delivery in the U.S. You would address the package to the post office for a particular ZIP code, which will hold it for 30 days until you pick it up after showing your ID:
If you are shipping by FedEx or UPS, you can also request to have items held for pickup at a nearby installation of theirs, or at an alternative delivery location. These alternative locations are intended to be used by businesses, not individuals, and you may not qualify to use all of them, but for example in some cases you can have UPS packages sent to Staples, an office supply retailer, and FedEx accepts qualified shipments to FedEx Office locations (formerly Kinko's).
By the same token, if you are ordering from a major retailer, most will make the package available for you to pick up at a nearby location, e.g. Home Depot, Best Buy, Walmart, and so on. Amazon.com and others have set up delivery lockers in some cities where you can pick up your order with an electronic code.