the person who owned it and had the contract with O2 can ring up and get the unlock code.
Otherwise bring it into one of the many shops that do phone unlocking usually cost under €20.
If you are computer savvy just google, there are companies online who will give you the unlock codes at a lower cost I have used these in the past.
If you are getting it unlocked sometimes you can have difficulty getting your internet data to work - i have used an app called Tweakker for this.