During your first hours in the world of Fallout 4 you will be forced to use mostly weaker weapons, however there's a smart way of gaining access to one of the most powerful guns very early in the campaign. The weapon we're talking about is the Cryolator and it is stored in Vault 111 (it's the location where you've started the game). Before you decide to go back to the Vault make sure that Dogmeat is following you - the first page of this chapter informs on how to find and add the dog to the team.
Use the elevator to reach Vault 111 and proceed to the Overseer's room. It's the same room where you've interacted with a terminal at the beginning of the game to open a door. Find a closed case displayed on the screens above.
The case has a master lock and theoretically you would have to wait until your character is at least on the eightheenth level and that he or she has the necessary perks to break the lock. Thankfully you can cheat the game and use Dogmeat to get the weapon for you. Turn towards the dog and start giving it orders. Command the animal to search the area for interactive items. Dogmeat should start moving towards the case with the legendary weapon (if the dog went somewhere else repeat your command).
Wait for Dogmeat to "remove" Cryolator from the case and to bring the weapon to you. Take the weapon from the ground. Don't worry that it doesn't have any ammunition, because ammo is in Dogmeat's "inventory" and all you have to do is transfer it to your inventory.
Important! Don't waste Cryolator's ammunition on fights with weaker enemies. Save this weapon for the most difficult battles!